home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Dev
/
misc
/
temgen.lha
/
Temgen
/
tg-0.11
/
sample
/
getopt
/
opdef.tg
< prev
next >
Wrap
Text File
|
2002-12-18
|
2KB
|
84 lines
#
# definitions for 'options.tg' example
#
@function init()
@ $options_defined = 0
@ $incl = 0
@ $optstring = ""
@ $types = [ i : "int", s : "char *" ]
@endfunction
@function include( name )
@if ( $incl.$name != 1 )
@ $incl.$name = 1
@ emit "include"
\#line $tplline() \"$tplfile()\"
\#include $name
@endif
@endfunction
@function option( letter, type, name, default )
@ if ( !$options_defined )
@ $options_defined = 1
@ $include( "<unistd.h>" )
@ emit "options"
\#line $tplline() \"$tplfile()\"
\
/* runtime options */
\
@ endif
@ emit "options"
\#line $tplline() \"$tplfile()\"
$types.$type $name \= $default ;
@ $optstring = $optstring + $letter
@ if ( $type == 's' )
@ $optstring = $optstring + ':'
@ endif
@ emit "case"
case \'$letter' :
@ switch $type
@ case 'i':
$name \= 1;
@ break
@ case 's':
$name \= optarg;
@ break
@ endswitch
@endfunction
@function main()
#
# program body:
#
@output( "stdout" )
@embed "include"
@embed "options"
\#line $tplline() \"$tplfile()\"
void parse_options( int argc, char *argv[] )
{
int opt = 0;
while( opt >= 0 ) {
opt = getopt( argc, argv, \"$optstring" );
switch( opt ) {
@embed "case"
\#line $tplline() \"$tplfile()\"
default:
break;
}
}
}
int main( int argc, char *argv[] )
{
parse_options( argc, argv );
return 0;
}
@endfunction